﻿using System;
using System.Web;

namespace PmfWeb.Core.HttpHandlers
{
    public abstract class BaseIPBlockModule : IHttpModule
    {
        protected abstract bool PassIP();
        protected abstract string RedirectUrl();

        public void Init(HttpApplication context)
        {
            context.BeginRequest += context_BeginRequest;
        }

        private void context_BeginRequest(object sender, EventArgs e)
        {
            HttpApplication application = sender as HttpApplication;
            if (!PassIP())
            {
                string url = RedirectUrl();
                if (application != null) application.Context.Response.Redirect(url == "" ? "http://www.5173.com/" : url);
            }
        }

        public void Dispose()
        {
            return;
        }
    }
}
